package com.xukehong.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.xukehong.demo.config.ApplicationContextProvider;
import com.xukehong.demo.service.payment.AbstractPaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: xkh
 * @Date: 2019/8/22 11:06
 * @Version 1.0
 */
@RestController
@RequestMapping("/pay")
@Api(tags = "支付")
@Slf4j
public class PayController {

    @Autowired
    private ApplicationContextProvider applicationContextProvider;

    /**
     * 下单之策略模式
     */
    @PreAuthorize("@ss.pro(\"xxx.xxx.xxx\")")
    @ApiOperation("下单之策略模式")
    @PostMapping("/payTest")
    public JSONObject test(@RequestBody JSONObject params, HttpServletRequest request) {
        //通过下单的商户号获取到通道编号(假如已在后台配置)
        String channelNumber = "pass1Pay";
        AbstractPaymentService service = applicationContextProvider.getBean(channelNumber, AbstractPaymentService.class);
        JSONObject jsonObject = service.payOrder(params, request);
        return jsonObject;
    }
}
